<?PHP

require_once WACT_ROOT . '/db/db.inc.php';
require_once WACT_ROOT . 'util/dataspace.inc.php';
require_once APP_ROOT.'model/common/site.php';

class Parameters {

	function getParameterName($type) {
    	switch ($type) {
          case 0:
            return "Domain name";
            break;
          case 1:
            return "Paypal email";
            break;
          case 2:
            return "Support email";
            break;
          case 3:
            return "Running mode";
            break;
          case 4:
            return "Number of front page articles";
            break;
          case 5:
            return "Number of recent articles";
            break;
          case 6:
            return "Teams Stats status";
            break;
          case 7:
            return "Video Status";
            break;
          case 8:
            return "Premium Video Status";
            break;
        }
	}

    // true - production
    // false - testing
	function getRunningMode() {
		$mode = Parameters::getParameter(3);
		return (boolean)$mode;
	}

	// enabled/disabled
	function getTeamStatsStatus() {
		$mode = Parameters::getParameter(6);
		return (boolean)$mode;
	}

	function getVideoStatus() {
		$mode = Parameters::getParameter(7);
		return (boolean)$mode;
	}

	function getPremiumVideoStatus() {
		$mode = Parameters::getParameter(8);
		return (boolean)$mode;
	}

	function getPaypalEmail() {
    	$email = Parameters::getParameter(1);
		return $email;
	}

    function getNumberFrontPageArticles() {
		$number = Parameters::getParameter(4);
		if (is_numeric( $number ) ) return $number;
		else return 5;
	}

    function getNumberRecentArticles() {
        $number = Parameters::getParameter(5);
        if (is_numeric( $number ) ) return $number;
		else return 7;
	}

	function getParameter($type) {
		$value = '';
		$site_id = Site::getSiteID();
		$sql = "select * from sport_parameters
		where type=$type
		and site_id = ".DBC::makeLiteral($site_id);
        $result = DBC::NewRecordSet($sql);
		$result->reset();
		if($result->next()) {
			$value = $result->get('value');
		}
		return $value;
	}

	function isExistParameter($type)  {
		$site_id = Site::getSiteID();
		$sql = "select * from sport_parameters
		where type=$type
		and site_id = ".DBC::makeLiteral($site_id);
        $result = DBC::NewRecordSet($sql);
		$result->reset();
		if ($result->next()) return true;
		else return false;
	}

    function saveParameter($type, $value) {
    	$site_id = Site::getSiteID();
        $isExist = Parameters::isExistParameter($type);
    	$data =& new DataSpace();
    	$data->set('value',$value);
        $data->set('`type`',$type);
        $data->set('site_id',$site_id);
        $Record =& DBC::NewRecord($data);
        if ($isExist)
        	$Record->update('sport_parameters', array('value','site_id'),
            "`type` = ". DBC::makeLiteral($type)." and site_id = ".DBC::makeLiteral($site_id) );
        else $Record->insertId('sport_parameters',
            array('`type`','value','site_id'), 'id');
    }




}


?>
